package com.xinqi.modules.exam.task.manager.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.mybatis.data.service.impl.BaseServiceImpl;
import com.xinqi.modules.exam.task.domain.AsyncTaskProcessLogEntity;
import com.xinqi.modules.exam.task.dto.req.AsyncTaskProcessLogQueryDTO;
import com.xinqi.modules.exam.task.dto.rsp.AsyncTaskProcessLogResultDTO;
import com.xinqi.modules.exam.task.manager.AsyncTaskProcessLogManager;
import com.xinqi.modules.exam.task.mapper.AsyncTaskProcessLogMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;

/**
 * 异步任务处理日志管理层实现
 *
 * @author: linkai
 * @date: 2023/07/08
 */
@Service
@RequiredArgsConstructor
public class AsyncTaskProcessLogManagerImpl extends BaseServiceImpl<AsyncTaskProcessLogMapper, AsyncTaskProcessLogEntity> implements AsyncTaskProcessLogManager {

    /**
     * 自定义分页查询
     */
    @Override
    public Page<AsyncTaskProcessLogResultDTO> findPage(Page<Object> page, AsyncTaskProcessLogQueryDTO query) {
        return this.baseMapper.findPage(page, query);
    }

    /**
     * 自定义列表查询
     */
    @Override
    public List<AsyncTaskProcessLogResultDTO> findList(AsyncTaskProcessLogQueryDTO query) {
        return this.baseMapper.findList(query);
    }

    /**
     * 根据id查询 异步任务处理日志数据
     */
    @Override
    public AsyncTaskProcessLogEntity findById(Long id) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(id), "ID不能为空");
        return getById(id);
    }

    /**
     * 根据id更新 异步任务处理日志数据，重写
     */
    @Override
    public boolean updateById(AsyncTaskProcessLogEntity entity) {
        return SqlHelper.retBool(getBaseMapper().updateById(entity));
    }

    /**
     * 根据id删除 异步任务处理日志数据
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(Long id) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(id), "ID不能为空");
        return this.removeById(id);
    }

}
